<?php
class interestController extends appController {
    
public function generalLearning($id=null,$sub_cat=null){
        
        $meta_val = serialize($sub_cat);

        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $check = $this->_model->checkboxvalidation('cat_name');

            if ($check!=null) {
                 $this->view->set('chk',$check);
             } 
             else{
                $id = $this->_model->updateInterest($id, INTEREST_GENERAL, $meta_val);
                
                if($id !== false){
                    header('Location: generalLearning');
                    exit;
                }
            }
                                
        }
        

        $getSubCats = $this->_model->getSubCats();
        $getInterest = $this->_model->getInterest(INTEREST_GENERAL);
        $this->view->set('getSubCats',$getSubCats);
        $this->view->set('getInterest',$getInterest[0]);
        return $this->view();
    }
    public function reindex(){
        
        
        $data = $this->_model->read(); 
                
        header('Content-Type: application/json; charset=utf-8');
        //echo "ok";
        $this->view->set('items',$data);
        return $this->view();
        
    }

        public function underGraduation( $id=null, $meta_key,$mytext, $university_name=null, $course_name=null, $year=null, $sem_name=null){

        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $meta_val = array("mytext"=>$mytext, "university_name"=>$university_name, "course_name"=>$course_name, "year"=>$year, "sem_name"=>$sem_name);
            $meta_val = serialize($meta_val);
            $error = $this->_model->validation();
            $check = $this->_model->checkboxvalidation('mytext');
                if ($check!=null) {
                    $this->view->set('chk',$check);
                }
             if($error){

                    $this->view->set('err',$error);
                     // return $this->view($error);
                }
                if($check == null && $error==null){
                $id = $this->_model->updateInterest($id, INTEREST_UNDER_GRADUATION, $meta_val);
                if($id !== false){
                    header('Location: underGraduation');
                    exit;
                }
            }
        }
              
        $undergradute = $this->_model->getInterest(INTEREST_UNDER_GRADUATION);
        $this->view->set('undergradute',$undergradute[0]);
        $getyears = $this->_model->getyears();
        $this->view->set('getyears',$getyears);
        $getsemesters = $this->_model->getsemesters();
        $this->view->set('getsemesters',$getsemesters);
        return $this->view();
    }
    public function underGrade($id=null, $school_board = null, $school_name = null, $class = null, $sem_name = null, $name = null){
        if($_SERVER["REQUEST_METHOD"]=='POST'){
                $meta_val = array("school_board"=>$school_board, "school_name"=>$school_name, "class"=>$class, "sem_name"=>$sem_name, "name"=>$name);
                $meta_val = serialize($meta_val);
                $error = $this->_model->validation();
                $check = $this->_model->checkboxvalidation('name');
                if ($check!=null) {
                    $this->view->set('chk',$check);
                }
             if($error){

                    $this->view->set('err',$error);
                     // return $this->view($error);
                }
                if($check == null && $error==null){
                $id = $this->_model->updateInterest($id, INTEREST_UNDER_GRADE, $meta_val);
                    if($id !== false){
                    header('Location: underGrade');
                    exit;
                }
            }
                                
             
        }
                
        $underGrade = $this->_model->getInterest(INTEREST_UNDER_GRADE);
        // print_r($underGrade);exit;
        $this->view->set('underGrade',$underGrade[0]);
        $getSubjects = $this->_model->getSubjects();
        $this->view->set('getSubjects',$getSubjects);
        $getsemesters = $this->_model->getsemesters();
        $this->view->set('getsemesters',$getsemesters);
        $getClasses = $this->_model->getClasses();
        $this->view->set('getClasses',$getClasses);
        return $this->view();
    }
    public function masters($id=null, $course_name = null, $year = null, $sem_name, $mytext = null){
        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $error = $this->_model->validation();
            

             if($error){

                     $this->view->set('err',$error);
                     return $this->view($error);
             }
             else{
            $meta_val = array("course_name"=>$course_name, "year"=>$year, "sem_name"=>$sem_name, "mytext"=>$mytext);
            
            $meta_val = serialize($meta_val);
                $id = $this->_model->updateInterest($id, INTEREST_MASTERS, $meta_val);
                                       
                if($id !== false){
                    header('Location: masters');
                    exit;
                }
            
                                
        }
    }
        $masters = $this->_model->getInterest(INTEREST_MASTERS);
    // print_r($masters);
        $this->view->set('masters',$masters[0]);
        $getyears = $this->_model->getyears();
        $this->view->set('getyears',$getyears);
        $getsemesters = $this->_model->getsemesters();
        $this->view->set('getsemesters',$getsemesters);
        return $this->view();
    }
}

    
